package com.hongyuan.sellfitness.ui.home.activity;

import android.os.Bundle;

import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.sellfitness.BR;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomActivity;
import com.hongyuan.sellfitness.databinding.ActivityStoreCardBinding;
import com.hongyuan.sellfitness.ui.home.view_mode.StoreCardViewModel;

public class StoreCardActivity extends CustomActivity<ActivityStoreCardBinding, StoreCardViewModel> {
    private String os_id;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_store_card;
    }

    @Override
    public int initVariableId() {
        //注意了：这里是小写的viewModel
        return BR.viewModel;
    }

    @Override
    public StoreCardViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用NetWorkViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(StoreCardViewModel.class);
    }

    @Override
    public void initParam() {
        os_id = getBundle().getString("os_id");
    }

    @Override
    public void initView() {
        super.initView();

        setOnRefresh(binding.refresh,REFRESH_0X3);
        setEnableLoadMore(Constants.GET_CARD_LIST);
        setEnableRefresh(Constants.GET_CARD_LIST);

        binding.comBack.setOnClickListener(view -> finish());
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.clearParams().setParams("os_id",os_id).setParams("os_ids",os_id).setParams("role_code","card");

        //请求门店权限（会籍卡）
        viewModel.requestData(Constants.VERIFY_ROLE);
    }
}
